Skip to content

Conversation

@heyseth
Copy link

@heyseth heyseth commented Oct 25, 2025

Related GitHub Issue

Closes: #4567

Description

This PR fixes checkpoint commits being written to the wrong repository when the user is in a Dev Container with the GIT_DIR environment variable configured.

Implementation approach:

Created a createSanitizedGit() helper function that creates SimpleGit instances with a sanitized environment, explicitly removing git-related environment variables (GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, GIT_OBJECT_DIRECTORY, GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_CEILING_DIRECTORIES) before executing git operations. This ensures checkpoint operations always target the intended shadow repository regardless of inherited environment.

The fix is applied at two points:

  1. Shadow repository initialization in create() method
  2. Cleanup operations in deleteCheckpoint() method

Key design choices:

  • Environment sanitization is scoped exclusively to checkpoint operations, ensuring other user workflows that may legitimately rely on GIT_DIR are unaffected
  • Used simple-git's .env() method to replace the inherited environment with our sanitized version

Reviewers should note:

  • The sanitization filters out environment variables at the point of creating the git instance, not globally
  • All existing checkpoint functionality remains unchanged; this is purely an environment isolation fix

Test Procedure

Automated testing:
Added a comprehensive integration test (isolates checkpoint operations from GIT_DIR environment variable) that:

  1. Creates a separate external git repository to simulate a GIT_DIR target
  2. Sets process.env.GIT_DIR to point to this external repo
  3. Creates a checkpoint in the workspace
  4. Verifies the commit appears in the shadow repo, NOT the external repo
  5. Confirms checkpoint restore functionality works correctly
  6. Properly cleans up environment state and temporary directories

Run the test suite:
npx vitest run services/checkpoints/__tests__/ShadowCheckpointService.spec.ts

Manual testing:
To verify the fix in a real Dev Container scenario:

  1. Build and package the extension: pnpm vsix
  2. Create a .devcontainer/devcontainer.json with:
{
  "remoteEnv": {
    "GIT_DIR": "/tmp/external-git/.git"
  }
}
  1. Start the Dev Container and install the packaged .vsix file
  2. Start a Roo session and trigger a checkpoint (make any code change with checkpoints enabled)
  3. Verify commits only appear in Roo's shadow repo (rooveterinaryinc.roo-cline/tasks/...), not in /tmp/external-git

Verification checklist:

  • ✅ Checkpoint commits stay in shadow repository when GIT_DIR is set in a Dev Container
  • ✅ Checkpoint restore functionality works correctly
  • ✅ Existing checkpoint workflows unaffected in normal environments

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Get in Touch

Discord: @ocean.smith


Important

Fixes checkpoint commit misdirection in Dev Containers by sanitizing git environment variables in ShadowCheckpointService.

  • Behavior:
    • Fixes checkpoint commits being written to the wrong repository when GIT_DIR is set in Dev Containers by sanitizing the environment.
    • createSanitizedGit() function added to remove git-related environment variables before git operations.
    • Applied in create() and deleteCheckpoint() methods of ShadowCheckpointService.
  • Testing:
    • Added integration test in ShadowCheckpointService.spec.ts to verify checkpoint isolation from GIT_DIR.
    • Test simulates external git repo, sets GIT_DIR, and verifies commits are in shadow repo.
  • Misc:
    • Uses simple-git's .env() method to set sanitized environment.
    • Logs removed git environment variables for debugging.

This description was created by Ellipsis for 3e1cbbf. You can customize this summary. It will automatically update as commits are pushed.

GIT_DIR environment

Fixes issue where checkpoint commits were written to the
wrong repository
when GIT_DIR environment variable was set in Dev
Containers.

Problem:
When developers use VS Code Dev Containers with remoteEnv
setting GIT_DIR,
Roo's checkpoint commits would land in the GIT_DIR location
instead of the
shadow repository, causing unintended commits and
confusion.

Root cause:
The simple-git library inherits the parent process
environment, and git
gives precedence to GIT_DIR over local .git directories.
Even though the
shadow repo was correctly initialized with core.worktree,
the inherited
GIT_DIR environment variable overrode repository detection.

Solution:
- Created createSanitizedGit() function that explicitly
unsets git-related
environment variables (GIT_DIR, GIT_WORK_TREE,
GIT_INDEX_FILE, etc.)
before creating SimpleGit instances for checkpoint
operations
- Applied sanitization at both shadow repo creation and
cleanup operations
- Added logging to help debug environment issues in Dev
Containers
- Environment isolation is scoped only to checkpoint
operations, preserving
other workflows that may rely on GIT_DIR

Testing:
Added comprehensive test that simulates GIT_DIR scenario
and verifies:
- Commits don't leak to external repositories
- Checkpoint save/restore operations work correctly
- Environment state is properly cleaned up
@heyseth heyseth requested review from cte, jr and mrubens as code owners October 25, 2025 00:58
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Oct 25, 2025
@roomote
Copy link

roomote bot commented Oct 25, 2025

Review Summary

I've reviewed the changes in this PR and identified one issue that needs to be addressed:

  • Test doesn't verify the real Dev Container scenario: The test sets GIT_DIR after service initialization, but the real issue occurs when GIT_DIR is set BEFORE initialization. The test should set the environment variable before creating the service to properly validate the fix.

All issues have been resolved.


View Job

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 25, 2025
The previous test set GIT_DIR after initializing the checkpoint service,
which didn't properly verify the fix. In real Dev Containers, GIT_DIR is
already set when Roo starts and creates the checkpoint service.

Changes:
- Initialize workspace repo before setting GIT_DIR (workspace already
  exists in real Dev Containers before GIT_DIR is set)
- Set GIT_DIR before creating the checkpoint service to properly test
  that sanitization works during service initialization
- Temporarily clear GIT_DIR when verifying external repo wasn't modified,
  then restore it to continue testing with GIT_DIR set

This ensures the test accurately simulates the Dev Container environment
and verifies that checkpoint operations are properly isolated despite
GIT_DIR being present during initialization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] Checkpoints commit to wrong repo when GIT_DIR is set (Dev Containers)

2 participants